package com.sikaryofficial.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.backend.annotation.TenantFilter;
import com.sikaryofficial.backend.domain.dto.req.workOrder.UserWorkOrderAcceptReq;
import com.sikaryofficial.backend.domain.dto.req.workOrder.UserWorkOrderListReq;
import com.sikaryofficial.backend.domain.dto.req.workOrder.UserWorkOrderSaveReq;
import com.sikaryofficial.backend.domain.dto.resp.workOrder.UserWorkOrderDTO;
import com.sikaryofficial.backend.domain.dto.resp.workOrder.UserWorkOrderDetailDTO;
import com.sikaryofficial.backend.manager.UserWorkOrderManager;
import com.sikaryofficial.common.core.utils.HiResultUtil;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.HiResult;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.common.log.annotation.Log;
import com.sikaryofficial.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户售后工单Controller
 *
 * @author qinjinyuan
 * @date 2024-01-17
 */
@RestController
@Api(tags = "用户售后工单")
@RequestMapping("/workOrder")
public class UserWorkOrderController extends BaseController {
    @Autowired
    private UserWorkOrderManager userWorkOrderManager;
    /**
     * 售后工单详情
     */
    @GetMapping("/{workOrderId}")
    @ApiOperation("售后工单详情")
    @TenantFilter
    public HiResult<UserWorkOrderDetailDTO> detail(@PathVariable(name = "workOrderId") Long workOrderId) {
        return HiResultUtil.success(userWorkOrderManager.detail(workOrderId));
    }

    /**
     * 新增用户售后工单
     */
    @Log(title = "保存用户售后工单", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @ApiOperation("保存用户售后工单")
    public HiResult<Boolean> add(@Validated @RequestBody UserWorkOrderSaveReq req) {
        return HiResultUtil.success(userWorkOrderManager.workOrderSave(req));
    }

    /**
     * 查询工单分页列表
     */
    @PostMapping("/listPage")
    @ApiOperation("查询工单分页列表")
    public PageResult<UserWorkOrderDTO> listPage(@Validated @RequestBody UserWorkOrderListReq req) {
        IPage<UserWorkOrderDTO> result = userWorkOrderManager.listPage(req);
        return PageUtil.success(result.getRecords(), result.getTotal());
    }

    /**
     * 查询工单分页列表
     */
    @PostMapping("/backendList")
    @ApiOperation("售后工单分页列表")
    @TenantFilter
    public PageResult<UserWorkOrderDTO> backendList(@Validated @RequestBody UserWorkOrderListReq req) {
        IPage<UserWorkOrderDTO> result = userWorkOrderManager.backendList(req);
        return PageUtil.success(result.getRecords(), result.getTotal());
    }
    /**
     * 删除用户售后工单
     */
    @Log(title = "删除用户售后工单", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{workOrderId}")
    @ApiOperation("删除用户售后工单")
    @TenantFilter
    public HiResult<Boolean> delete(@PathVariable(name = "workOrderId") Long workOrderId ) {
        return HiResultUtil.success(userWorkOrderManager.delete(workOrderId));
    }
    @Log(title = "工单受理", businessType = BusinessType.UPDATE)
    @PostMapping("/accept")
    @ApiOperation("工单受理")
    @TenantFilter
    public HiResult<Boolean> accept(@Validated @RequestBody UserWorkOrderAcceptReq req) {
        return HiResultUtil.success(userWorkOrderManager.accept(req));
    }

}
